package Operation;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-04-13
 * Time: 15:45
 * To BE A Better Person-2020-3-2
 */

import Book.BookList;

import java.util.Scanner;

/**
 * 删除图书
 */
//shuidaima
    //SHUI
    //MTYD
public class DelOp implements IOoperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("输入你想删除的书名>:");
        Scanner sc=new Scanner(System.in);
        String del_name=sc.nextLine();
        for (int i = 0; i < bookList.Used; i++) {
            if(bookList.books[i].getName().equals(del_name)){
                for (int j = i; j <bookList.Used-1 ; j++) {
                    bookList.books[j].setName(bookList.books[j+1].getName());
                    bookList.books[j].setAuthor(bookList.books[j+1].getAuthor());
                    bookList.books[j].setPrice(bookList.books[j+1].getPrice());
                    bookList.books[j].setType(bookList.books[j+1].getType());
                    bookList.books[j].setBorrowed(bookList.books[j+1].isBorrowed());
                }
                break;
            }
        }
        bookList.Used--;
        System.out.println("==========删除成功========");
    }
}
